<template>
  <div class="about">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>组织管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!-- 搜索与添加部门区 -->
      <el-form :inline="true" ref="info" :model="info">
        <el-form-item prop="name">
          <el-input
            v-model="info.name"
            style="width: 150px"
            placeholder="请输入姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item prop="sex">
          <el-select
            style="width: 150px"
            v-model="info.sex"
            placeholder="请选择性别"
            clearable
          >
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="jobInfo.job">
          <el-input
            v-model="info.jobInfo.job"
            style="width: 150px"
            placeholder="请输入岗位"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item prop="jobInfo.department">
          <el-input
            v-model="info.jobInfo.department"
            style="width: 150px"
            placeholder="请输入部门"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
          <el-input
            v-model="info.jobInfo.deleted"
            style="width: 150px"
            placeholder="请输入状态"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button
            type="success"
            size="medium"
            @click="resetForm('info')"
            round
            >重置</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="medium" @click="getUserList" round
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <el-row>
        <el-col :span="4"
          ><el-button type="primary" @click="addDialogVisible = true"
            >添加用户</el-button
          ></el-col
        >
      </el-row>
      <!-- 用户列表区 -->
      <el-table border stripe :data="userList">
        <el-table-column label="序号" type="index"> </el-table-column>
        <el-table-column label="工号" prop="jobNumber"> </el-table-column>
        <el-table-column label="员工姓名" prop="name"> </el-table-column>
        <el-table-column label="用户名" prop="username"> </el-table-column>
        <el-table-column label="员工电话" prop="phone"> </el-table-column>
        <el-table-column label="员工生日" prop="birthday"> </el-table-column>
        <!-- <el-table-column label="员工账号密码" prop="password">
        </el-table-column> -->
        <el-table-column label="性别" prop="sex"> </el-table-column>
        <el-table-column
          label="员工身份证号码"
          prop="idCardNumber"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column label="员工邮箱" prop="email" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          label="毕业学校"
          prop="graduationSchool"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column label="入职时间" prop="jobInfo.entryTime">
        </el-table-column>
        <el-table-column label="部门" prop="jobInfo.department">
        </el-table-column>
        <el-table-column label="工作邮箱" prop="jobInfo.workEmail">
        </el-table-column>
        <el-table-column label="岗位" prop="jobInfo.job"> </el-table-column>
        <el-table-column label="聘用形式" prop="jobInfo.hireForm">
        </el-table-column>
        <el-table-column label="转正日期" prop="jobInfo.positiveTime">
        </el-table-column>
        <el-table-column label="转正状态" prop="jobInfo.positiveState">
        </el-table-column>
        <el-table-column label="转正评价" prop="jobInfo.positiveEvaluation">
        </el-table-column>
        <el-table-column label="职级" prop="jobInfo.rank"> </el-table-column>
        <el-table-column label="汇报对象" prop="jobInfo.reportingObject">
        </el-table-column>
        <el-table-column label="调整司龄" prop="jobInfo.adjustAge">
        </el-table-column>
        <el-table-column label="司龄" prop="jobInfo.timeInCompany">
        </el-table-column>
        <el-table-column label="工龄" prop="jobInfo.timeInWork">
        </el-table-column>
        <el-table-column label="纳税城市" prop="jobInfo.taxCity">
        </el-table-column>
        <el-table-column label="合同开始时间" prop="jobInfo.contractStartTime">
        </el-table-column>
        <el-table-column
          label="合同结束时间"
          prop="jobInfo.contractExpiresTime"
        >
        </el-table-column>
        <!-- <el-table-column label="状态" prop="deleted"> </el-table-column> -->

        <el-table-column label="操作" width="145px">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="showEditDialog(scope.row.jobNumber)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click="remove(scope.row.jobNumber)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="info.currentPage"
        :page-sizes="[2, 4, 8, 10]"
        :page-size="info.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 添加用户信息对话框 -->
      <el-dialog
        title="添加用户信息"
        :visible.sync="addDialogVisible"
        width="60%"
        @close="addDialogClosed"
      >
        <!-- 内容主题区 -->
        <el-form
          :inline="true"
          :model="addForm"
          :rules="addFormRules"
          ref="addFormRef"
          label-width="100px"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工姓名" prop="name">
                <el-input v-model="addForm.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="员工性别" prop="sex">
                <el-select v-model="addForm.sex" placeholder="请选择员工性别">
                  <el-option label="男" value="男"></el-option>
                  <el-option label="女" value="女"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="员工电话" prop="phone">
                <el-input v-model="addForm.phone"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="身份证号" prop="idCardNumber">
                <el-input v-model="addForm.idCardNumber"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-form-item label="员工生日" prop="birthday">
            <el-date-picker v-model="addForm.birthday"></el-date-picker>
          </el-form-item> -->
          <!-- <el-form-item label="员工账号密码" prop="password">
            <el-input v-model="addForm.password"></el-input>
          </el-form-item> -->
          <!-- <el-form-item label="员工身份证号码" prop="idCardNumber">
            <el-input v-model="addForm.idCardNumber"></el-input>
          </el-form-item> -->
          <!-- <el-form-item label="员工邮箱" prop="email">
            <el-input v-model="addForm.email"></el-input>
          </el-form-item>
          <el-form-item label="毕业学校" prop="graduationSchool">
            <el-input v-model="addForm.graduationSchool"></el-input>
          </el-form-item> -->
          <el-row>
            <!-- <el-col :span="12">
              <el-form-item label="入职时间" prop="entryTimed">
                <el-date-picker
                  v-model="addForm.jobInfo.entryTimed"
                ></el-date-picker>
              </el-form-item> </el-col
            >
            <el-col :span="12"> -->
            <el-col :span="12">
              <el-form-item label="部门名称" prop="department">
                <el-select v-model="addForm.jobInfo.department">
                  <el-option
                    v-for="item in bum"
                    :key="item.id"
                    :label="item.name"
                    :value="item"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="角色名称" prop="roleName">
                <el-select v-model="addForm.roleName">
                  <el-option
                    v-for="item in role"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="工作邮箱" prop="workEmail">
                <el-input v-model="addForm.jobInfo.workEmail"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="聘用形式" prop="hireForm">
                <el-input v-model="addForm.jobInfo.hireForm"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="岗位" prop="job">
                <el-input v-model="addForm.jobInfo.job"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="转正评价" prop="positiveEvaluation">
                <el-input
                  v-model="addForm.jobInfo.positiveEvaluation"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="转正状态" prop="positiveState">
                <el-input v-model="addForm.jobInfo.positiveState"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="转正日期" prop="positiveTime">
                <el-date-picker
                  v-model="addForm.jobInfo.positiveTime"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="职级" prop="rank">
                <el-input v-model="addForm.jobInfo.rank"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="汇报对象" prop="reportingObject">
                <el-input v-model="addForm.jobInfo.reportingObject"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="调整司龄" prop="adjustAge">
                <el-input v-model="addForm.jobInfo.adjustAge"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="司龄" prop="timeInCompany">
                <el-input v-model="addForm.jobInfo.timeInCompany"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="工龄" prop="timeInWork">
                <el-input v-model="addForm.jobInfo.timeInWork"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="纳税城市" prop="taxCity">
                <el-input v-model="addForm.jobInfo.taxCity"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="合同开始时间" prop="contractStartTime">
                <el-date-picker
                  v-model="addForm.jobInfo.contractStartTime"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同结束时间" prop="contractExpiresTime">
                <el-date-picker
                  v-model="addForm.jobInfo.contractExpiresTime"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="入职时间" prop="entryTimed">
                <el-date-picker
                  v-model="addForm.jobInfo.entryTimed"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-form-item label="开户行" prop="bank">
            <el-input v-model="addForm.bank"></el-input>
          </el-form-item>
          <el-form-item label="银行卡号" prop="bankCard">
            <el-input v-model="addForm.bankCard"></el-input>
          </el-form-item>
          <el-form-item label="学历" prop="educationalBackground">
            <el-input v-model="addForm.educationalBackground"></el-input>
          </el-form-item>
          <el-form-item label="紧急联系人" prop="emergencyContact">
            <el-input v-model="addForm.emergencyContact"></el-input>
          </el-form-item>
          <el-form-item label="紧急联系人电话" prop="emergencyPhone">
            <el-input v-model="addForm.emergencyPhone"></el-input>
          </el-form-item>
          <el-form-item label="毕业时间" prop="graduationTime">
            <el-date-picker v-model="addForm.graduationTime"></el-date-picker>
          </el-form-item> -->
          <!-- <el-form-item label="身份证照片" prop="idCardPhoto">
            <el-input v-model="addForm.idCardPhoto"></el-input>
          </el-form-item> -->
          <!-- <el-form-item label="是否生育" prop="isFertility">
            <el-input v-model="addForm.isFertility"></el-input>
          </el-form-item>
          <el-form-item label="婚姻状况" prop="isMarriage">
            <el-input v-model="addForm.isMarriage"></el-input>
          </el-form-item>
          <el-form-item label="民族" prop="national">
            <el-input v-model="addForm.national"></el-input>
          </el-form-item>
          <el-form-item label="专业" prop="professional">
            <el-input v-model="addForm.professional"></el-input>
          </el-form-item>
          <el-form-item label="员工户口所在地" prop="registeredResidence">
            <el-input v-model="addForm.registeredResidence"></el-input>
          </el-form-item>
          <el-form-item label="社保账号" prop="socialSecurity">
            <el-input v-model="addForm.socialSecurity"></el-input>
          </el-form-item> -->
        </el-form>
        <span slot="footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addUser">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 用户信息编辑表单 -->
      <el-dialog
        title="查询修改用户信息"
        :visible.sync="editDialogVisible"
        width="60%"
        @close="editDialogClosed"
      >
        <el-form
          :inline="true"
          :model="editForm"
          :rules="editFormRules"
          ref="editFormRef"
          label-width="100px"
        >
          <!-- <el-form-item label="id" prop="id">
            <el-input v-model="editForm.id"></el-input>
          </el-form-item> -->
          <el-form-item label="工号" prop="jobNumber">
            <el-input v-model="editForm.jobNumber"></el-input>
          </el-form-item>
          <el-form-item label="员工姓名" prop="name">
            <el-input v-model="editForm.name"></el-input>
          </el-form-item>
          <!-- <el-form-item label="状态" prop="deleted">
            <el-input v-model="editForm.deleted"></el-input>
          </el-form-item> -->
          <el-form-item label="用户名" prop="username">
            <el-input v-model="editForm.username"></el-input>
          </el-form-item>
          <el-form-item label="员工性别" prop="sex">
            <el-input v-model="editForm.sex"></el-input>
          </el-form-item>
          <el-form-item label="员工电话" prop="phone">
            <el-input v-model="editForm.phone"></el-input>
          </el-form-item>
          <!-- <el-form-item label="员工生日" prop="birthday">
            <el-input v-model="editForm.birthday"></el-input>
          </el-form-item> -->
          <el-form-item label="账号密码" prop="password">
            <el-input v-model="editForm.password"></el-input>
          </el-form-item>
          <el-form-item label="身份证号" prop="idCardNumber">
            <el-input v-model="editForm.idCardNumber"></el-input>
          </el-form-item>
          <!-- <el-form-item label="员工邮箱" prop="email">
            <el-input v-model="editForm.email"></el-input>
          </el-form-item>
          <el-form-item label="毕业学校" prop="graduationSchool">
            <el-input v-model="editForm.graduationSchool"></el-input>
          </el-form-item> -->

          <el-form-item label="入职时间" prop="entryTime">
            <el-input v-model="editForm.jobInfo.entryTime"></el-input>
          </el-form-item>
          <el-form-item label="所属部门" prop="department">
            <el-input v-model="editForm.jobInfo.department"></el-input>
          </el-form-item>
          <el-form-item label="工作邮箱" prop="workEmail">
            <el-input v-model="editForm.jobInfo.workEmail"></el-input>
          </el-form-item>
          <el-form-item label="聘用形式" prop="hireForm">
            <el-input v-model="editForm.jobInfo.hireForm"></el-input>
          </el-form-item>
          <el-form-item label="岗位" prop="job">
            <el-input v-model="editForm.jobInfo.job"></el-input>
          </el-form-item>
          <el-form-item label="转正评价" prop="positiveEvaluation">
            <el-input v-model="editForm.jobInfo.positiveEvaluation"></el-input>
          </el-form-item>
          <el-form-item label="转正状态" prop="positiveState">
            <el-input v-model="editForm.jobInfo.positiveState"></el-input>
          </el-form-item>
          <el-form-item label="转正日期" prop="positiveTime">
            <el-input v-model="editForm.jobInfo.positiveTime"></el-input>
          </el-form-item>
          <el-form-item label="职级" prop="rank">
            <el-input v-model="editForm.jobInfo.rank"></el-input>
          </el-form-item>
          <el-form-item label="汇报对象" prop="reportingObject">
            <el-input v-model="editForm.jobInfo.reportingObject"></el-input>
          </el-form-item>
          <el-form-item label="调整司龄" prop="adjustAge">
            <el-input v-model="editForm.jobInfo.adjustAge"></el-input>
          </el-form-item>
          <el-form-item label="司龄" prop="timeInCompany">
            <el-input v-model="editForm.jobInfo.timeInCompany"></el-input>
          </el-form-item>
          <el-form-item label="工龄" prop="timeInWork">
            <el-input v-model="editForm.jobInfo.timeInWork"></el-input>
          </el-form-item>
          <el-form-item label="纳税城市" prop="taxCity">
            <el-input v-model="editForm.jobInfo.taxCity"></el-input>
          </el-form-item>
          <el-form-item label="合同开始时间" prop="contractStartTime">
            <el-input v-model="editForm.jobInfo.contractStartTime"></el-input>
          </el-form-item>
          <el-form-item label="合同结束时间" prop="contractExpiresTime">
            <el-input v-model="editForm.jobInfo.contractExpiresTime"></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="editInfo">确定修改</el-button>
        </span>
      </el-dialog>
      -->
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    // 校验电话号码
    // var checkMobile = (rule, value, cb) => {
    //   //验证手机号码的正则表达式
    //   const regMobile = /^[1][3,4,5,7,8][0-9]{9}$/;
    //   if (regMobile.test(value)) {
    //     return cb();
    //   }
    //   cb(new Error("请输入合法的电话号码"));
    // };

    // // 校验邮箱
    // var checkEmail = (rule, value, cb) => {
    //   //验证邮箱的正则表达式
    //   const regEmail =
    //     /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
    //   if (regEmail.test(value)) {
    //     //合法邮箱
    //     return cb();
    //   }
    //   cb(new Error("请输入合法的邮箱"));
    // };
    return {
      info: {
        jobInfo: {
          deleted: "",
          department: "",
          job: "",
        },
        pageSize: 10,
        currentPage: 1,
        name: "",
        sex: "",
      },
      userList: [],
      total: 0,
      // 添加用户对话框隐藏
      addDialogVisible: false,
      role: [
        {
          value: "普通用户",
          label: "普通用户",
        },
        {
          value: "组长",
          label: "组长",
        },
        {
          value: "部门经理",
          label: "部门经理",
        },
        {
          value: "总经理",
          label: "总经理",
        },
        {
          value: "财务",
          label: "财务",
        },
        {
          value: "人事",
          label: "人事",
        },
      ],
      //添加用户的表单数据
      addForm: {
        name: "",
        phone: "",
        sex: "",
        idCardNumber: "",
        roleName: "",
        jobInfo: {
          entryTimed: "",
          department: "",
          workEmail: "",
          job: "",
          hireForm: "",
          positiveTime: "",
          positiveState: "",
          positiveEvaluation: "",
          rank: "",
          reportingObject: "",
          adjustAge: "",
          timeInCompany: "",
          timeInWork: "",
          taxCity: "",
          contractStartTime: "",
          contractExpiresTime: "",
        },
        // id: "",
        // jobNumber: "",
        // birthday: "",
        // password: "",
        // email: "",
        // graduationSchool: "",

        // bank: "",
        // bankCard: "",
        // educationalBackground: "",
        // emergencyContact: "",
        // emergencyPhone: "",
        // deleted: "",
        // username: "",
        // graduationTime: "",
        // idCardPhoto: "",
        // isFertility: "",
        // isMarriage: "",
        // national: "",
        // professional: "",
        // registeredResidence: "",
        // socialSecurity: "",
      },
      //添加表单的规则验证对象
      addFormRules: {
        // name: [
        //   { required: true, message: "请输入员工姓名", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 5,
        //     message: "员工姓名为1~5个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // sex: [{ required: true, message: "请选择员工性别", trigger: "blur" }],
        // phone: [
        //   { required: true, message: "请输入员工电话号码", trigger: "blur" },
        //   {
        //     validator: checkMobile,
        //     trigger: "blur",
        //   },
        // ],
        // email: [
        //   { required: true, message: "请输入员工邮箱", trigger: "blur" },
        //   {
        //     validator: checkEmail,
        //     trigger: "blur",
        //   },
        // ],
        // birthday: [
        //   { required: true, message: "请输入员工生日", trigger: "blur" },
        // ],
        // password: [
        //   { required: true, message: "请输入员工账号密码", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "员工账号密码为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // idCardNumber: [
        //   { required: true, message: "请输入员工身份证号码", trigger: "blur" },
        //   {
        //     max: 18,
        //     message: "员工身份证号码为18个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // graduationSchool: [
        //   { required: true, message: "请输入毕业学校", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "毕业学校为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // jobInfo:{
        // entryTime: [
        //    { required: true, message: "请输入部门名称", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "部门名称为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // department: [
        //   { required: true, message: "请输入部门名称", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "部门名称为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // workEmail: [
        //   { required: true, message: "请输入工作邮箱", trigger: "blur" },
        //   {
        //     validator: checkEmail,
        //     trigger: "blur",
        //   },
        // ],
        // hireForm: [
        //   { required: true, message: "请输入聘用形式", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "聘用形式为2~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // job: [
        //   { required: true, message: "请输入岗位名称", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "岗位名称为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // positiveEvaluation: [
        //   { required: true, message: "请输入转正评价", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 500,
        //     message: "转正评价为1~500个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // positiveState: [
        //   { required: true, message: "请输入转正状态", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "转正状态为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // positiveTime: [
        //   { required: true, message: "请输入转正日期", trigger: "blur" },
        // ],
        // rank: [
        //   { required: true, message: "请输入职级", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 50,
        //     message: "职级为1~50个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // reportingObject: [
        //   { required: true, message: "请输入汇报对象", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 20,
        //     message: "汇报对象为1~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // adjustAge: [
        //   { required: true, message: "请输入调整司龄", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 2,
        //     message: "调整司龄为1~2个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // timeInCompany: [
        //   { required: true, message: "请输入司龄", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 2,
        //     message: "司龄为1~2个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // timeInWork: [
        //   { required: true, message: "请输入工龄", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 2,
        //     message: "工龄为1~2个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // taxCity: [
        //   { required: true, message: "请输入纳税城市", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 20,
        //     message: "纳税城市为1~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // contractStartTime: [
        //   { required: true, message: "请输入合同开始时间", trigger: "blur" },
        // ],
        // contractExpiresTime: [
        //   { required: true, message: "请输入合同结束时间", trigger: "blur" },
        // ],
        // },
        // bank: [
        //   { required: true, message: "请输入开户行", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "开户行为2~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // bankCard: [
        //   { required: true, message: "请输入银行卡号", trigger: "blur" },
        //   {
        //     max: 19,
        //     message: "银行卡号为19个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // educationalBackground: [
        //   { required: true, message: "请输入学历", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "学历为2~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // emergencyContact: [
        //   { required: true, message: "请输入紧急联系人", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 5,
        //     message: "紧急联系人为2~5个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // emergencyPhone: [
        //   { required: true, message: "请输入紧急联系人电话", trigger: "blur" },
        //   {
        //     validator: checkMobile,
        //     trigger: "blur",
        //   },
        // ],
        // graduationTime: [
        //   { required: true, message: "请输入毕业时间", trigger: "blur" },
        // ],
        // idCardPhoto: [
        //   { required: true, message: "请输入身份证照片", trigger: "blur" },
        // ],
        // isFertility: [
        //   { required: true, message: "请输入是否生育", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 5,
        //     message: "是否生育为1~5个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // isMarriage: [
        //   { required: true, message: "请输入婚姻状况", trigger: "blur" },
        //   {
        //     max: 2,
        //     message: "婚姻状况为2个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // national: [
        //   { required: true, message: "请输入民族", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "民族为2~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // professional: [
        //   { required: true, message: "请输入专业", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "专业为2~20个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // registeredResidence: [
        //   { required: true, message: "请输入员工户口所在地", trigger: "blur" },
        //   {
        //     min: 2,
        //     max: 100,
        //     message: "员工户口所在地为2~100个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        // socialSecurity: [
        //   { required: true, message: "请输入社保账号", trigger: "blur" },
        //   {
        //     max: 18,
        //     message: "社保账号为18个字符之间",
        //     trigger: "blur",
        //   },
        // ],
      },
      //编辑部门信息对话框隐藏
      editDialogVisible: false,
      //查询到的用户信息对象
      editForm: {
        jobInfo: {},
      },
      //编辑部门信息规则
      editFormRules: {},
      bum: [],
    };
  },
  created() {
    this.info.pageSize = 10;
    this.info.currentPage = 1;
    this.getUserList();
    this.department();
  },
  mounted() {
    // //监听window.onresize事件
    // window.onresize = () => {
    //   return (() => {
    //     this.setDialogWidth();
    //   })();
    // };
  },
  methods: {
    //重置
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

    //获取用户信息
    async getUserList() {
      // const params = {
      //   currentPage: this.info.currentPage,
      //   pageSize: this.info.pageSize,
      //   // pageSize: this.queryParam.pageSize
      // };
      await this.$http
        .post("organization/employeeQuery", this.info)
        .then((res) => {
          console.log(res);
          if (res.data.flag !== true) {
            return this.$message.error("获取用户信息失败!");
          }
          this.userList = res.data.rows;
          this.total = res.data.total;
        });
    },
    //监听信息条数
    handleSizeChange(newSize) {
      // console.log(newSize);
      this.info.pageSize = newSize;
      console.log(this.info.pageSize);
      this.getUserList();
    },
    handleCurrentChange(newPage) {
      // console.log(newPage);
      this.info.currentPage = newPage;
      this.getUserList();
    },
    //监听添加用户表单的关闭事件
    addDialogClosed() {
      this.$refs.addFormRef.resetFields();
    },
    //点击按钮添加用户信息
    addUser() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;
        //可以发起添加用户信息的网络请求
        const { data: res } = await this.$http.put(
          "organization/insertEmployee",
          this.addForm
        );
        console.log(res);
        if (res.flag !== true) {
          return this.$message.error("添加用户信息失败!");
        }
        this.$message.success("添加用户信息成功!");
        this.addDialogVisible = false;
        this.getUserList();
      });
    },
    //点击按钮编辑用户信息
    async showEditDialog(jobNumber) {
      console.log(jobNumber);
      const { data: res } = await this.$http.get(
        "organization/selectEmployeeByJobNumber",
        {
          params: { jobNumber },
        }
      );
      console.log(res);
      if (res.flag !== true) {
        return this.$message.error("获取用户信息失败!");
      }
      this.editForm = res.data;
      this.editDialogVisible = true;
    },
    // 监听修改用户信息对话框的关闭事件
    editDialogClosed() {
      this.$refs.editFormRef.resetFields();
    },
    //修改用户信息并提交
    editInfo() {
      // console.log(jobNumber)
      this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return;
        //发起修改用户信息请求
        const { data: res } = await this.$http.post(
          "organization/updateEmployee",
          {
            jobNumber: this.editForm.jobNumber,
            id: this.editForm.id,
            name: this.editForm.name,
            sex: this.editForm.sex,
            phone: this.editForm.phone,
            birthday: this.editForm.birthday,
            password: this.editForm.password,
            idCardNumber: this.editForm.idCardNumber,
            email: this.editForm.email,
            graduationSchool: this.editForm.graduationSchool,
            jobInfo: {
              entryTime: this.editForm.jobInfo.entryTime,
              department: this.editForm.jobInfo.department,
              workEmail: this.editForm.jobInfo.workEmail,
              hireForm: this.editForm.jobInfo.hireForm,
              job: this.editForm.jobInfo.job,
              positiveEvaluation: this.editForm.jobInfo.positiveEvaluation,
              positiveState: this.editForm.jobInfo.positiveState,
              positiveTime: this.editForm.jobInfo.positiveTime,
              rank: this.editForm.jobInfo.rank,
              reportingObject: this.editForm.jobInfo.reportingObject,
              adjustAge: this.editForm.jobInfo.adjustAge,
              timeInCompany: this.editForm.jobInfo.timeInCompany,
              timeInWork: this.editForm.jobInfo.timeInWork,
              taxCity: this.editForm.jobInfo.taxCity,
              contractStartTime: this.editForm.jobInfo.contractStartTime,
              contractExpiresTime: this.editForm.jobInfo.contractExpiresTime,
            },
            deleted: this.editForm.deleted,
            username: this.editForm.username,
          }
        );
        if (res.flag !== true) {
          return this.$message.error("修改用户信息失败");
        }
        //关闭对话框
        this.editDialogVisible = false;
        //提示修改信息成功
        this.$message.success("修改用户信息成功");
        //获取新的用户信息
        this.getUserList();
      });
    },
    //删除用户信息
    async remove(jobNumber) {
      console.log(jobNumber);
      const confirmResult = await this.$confirm(
        "此操作将永久删除该用户, 是否继续?",
        "删除用户",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      if (confirmResult !== "confirm") {
        return this.$message.info("已经取消删除！");
      }
      const { data: res } = await this.$http.delete(
        "organization/deleteEmployee/",
        { params: { jobNumber } }
      );
      console.log(res);

      if (res.flag !== true) {
        return this.$message.error("删除用户信息失败");
      }
      this.$message.success("删除用户信息成功");
      this.getUserList();
    },
    //获取部门信息
    async department() {
      const { data: res } = await this.$http.get(
        "organization/selectDepartmentNames"
      );
      this.bum = res.data;
      console.log(res);
    },
  },
};
</script>

<style scoped></style>
